<template>
    <a-modal
        title="供应商选择"
        :visible="visible"
        @ok="handleOk"
        @cancel="visible = false"
        class="large-modal"
    >
        <searchData :searchData="searchArr" @search="search"></searchData>
        <b-table
            ref="table"
            :request="loadData"
            :selectConfig="{use:true,type:'radio',rowKey:'id'}"
            :pageKeys="['pageNo', 'pageSize','totalSize']"
            :columns="columns"
            @row-click="(e,row) => this.selectRow = row">
            <span slot="num" slot-scope="text, record, index">{{ index + 1 }}</span>
        </b-table>
    </a-modal>
</template>
<script>
import { pubSupplierList } from '@/api/material/public/public'

export default {
    name: 'detail-dialog',
    props: {
        otherUrl: {
            type: [Object,Function],
            default() {
                return null
            }
        },
        otherData: {
            type: Object,
            default() {
                return null
            }
        }
    },
    data() {
        return {
            visible: false,
            columns: [
                {
                    title: '序号',
                    scopedSlots: { customRender: 'num' }
                },
                {
                    title: '供应商名称',
                    dataIndex: 'name'
                },
                {
                    title: '供应商编码',
                    dataIndex: 'code'
                },
                {
                    title: '联系人',
                    dataIndex: 'contacts'
                },
                {
                    title: '电话',
                    dataIndex: 'phone'
                }
            ],
            searchArr: [
                {
                    name: '供应商名称',
                    value: 'name',
                    type: 'input'
                },
                {
                    name: '供应商编码',
                    value: 'code',
                    type: 'input'
                }
            ],
            selectRow: null,
            queryParams: {},
            loadData: params => {
                console.log(this.otherUrl)
                if (this.otherUrl) {
                    let searchData = Object.assign(this.otherData, params, this.queryParams)
                    return this.otherUrl(searchData)
                } else {
                    let searchData = Object.assign(params, this.queryParams)
                    if (this.queryParams && Object.keys(this.queryParams).length && searchData.status) {
                    } else {
                        searchData.status = 1
                    }
                    searchData.auditStatus = 'PAST'
                    return pubSupplierList(searchData)
                }
            }
        }
    },
    methods: {
        open() {
            this.visible = true
        },
        handleOk: function() {
            if (!this.selectRow) {
                this.$message.error('请选择基础数据')
                return
            }
            this.visible = false
            this.$emit('createList', this.selectRow)
        },
        search(val) {
            this.queryParams = val || {}
            this.$refs.table.getData(null, true)
        }
    }
}
</script>
